package com.gooluke.auth.util;

import com.gooluke.auth.enums.AuthException;
import com.gooluke.auth.exception.BusinessException;

/**
 * @author gooluke
 * description
 * datetime 2025-03-28 15:59
 */
public class ExceptionUtil {

    public static void throwDefaultException() {
        throwDefaultException("系统繁忙，请稍后重试~");
    }

    public static void throwDefaultException(String message) {
        throw new BusinessException(message);
    }

    public static void throwDefaultException(AuthException authException) {
        throw new BusinessException(authException);
    }

    public static void throwException(AuthException authException) {
        if (authException.getException() == null) {
            throwDefaultException(authException);
        }
        try {
            throw authException.getException().getDeclaredConstructor(String.class).newInstance(authException.getMessage());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
